package com.party.core.service.notify.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.notify.NotifySysMessageReadDao;
import com.party.core.dao.write.notify.NotifySysMessageWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.notify.NotifySysMessage;
import com.party.core.service.notify.INotifySysMessageService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 系统消息推送服务接口实现
 *
 * @author yifeng
 * @date 2018/6/25 0025
 * @time 上午 11:14
 */
@Service
public class NotifySysMessageService implements INotifySysMessageService {
    @Autowired
    private NotifySysMessageReadDao notifySysMessageReadDao;
    @Autowired
    private NotifySysMessageWriteDao notifySysMessageWriteDao;

    @Override
    public String insert(NotifySysMessage sysMessage) {
        BaseModel.preInsert(sysMessage);
        boolean result = notifySysMessageWriteDao.insert(sysMessage);
        if (result) {
            return sysMessage.getId();
        }
        return null;
    }

    @Override
    public boolean update(NotifySysMessage sysMessage) {
        sysMessage.setUpdateDate(new Date());
        return notifySysMessageWriteDao.update(sysMessage);
    }

    @Override
    public boolean deleteLogic(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return notifySysMessageWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return notifySysMessageWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return notifySysMessageWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return notifySysMessageWriteDao.batchDelete(ids);
    }

    @Override
    public NotifySysMessage get(String id) {
        return notifySysMessageReadDao.get(id);
    }

    @Override
    public List<NotifySysMessage> listPage(NotifySysMessage sysMessage, Page page) {
        return notifySysMessageReadDao.listPage(sysMessage, page);
    }

    @Override
    public List<NotifySysMessage> list(NotifySysMessage sysMessage) {
        return notifySysMessageReadDao.listPage(sysMessage, null);
    }

    @Override
    public List<NotifySysMessage> batchList(Set<String> ids, NotifySysMessage sysMessage, Page page) {
        return notifySysMessageReadDao.batchList(ids, new HashedMap(), page);
    }

    @Override
    public List<NotifySysMessage> webListPage(NotifySysMessage sysMessage, Map<String, Object> params, Page page) {
        return notifySysMessageReadDao.webListPage(sysMessage, params, page);
    }
}
